package com.seven.http;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @工程名:common-utils
 * @author: sevenDay
 * @时间: 2018/12/20 12:25
 * @描述:
 */
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext APPLICATION_CONTEXT;

    static ApplicationContext getApplicationContext() {
        return APPLICATION_CONTEXT;
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        if (APPLICATION_CONTEXT == null) {
            APPLICATION_CONTEXT = applicationContext;
        }
    }
    public static Object getBean(String name) {
        return APPLICATION_CONTEXT.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return APPLICATION_CONTEXT.getBean(clazz);
    }

}
